Add optional PostgreSQL native materializer#61
Open
sam-saffron-jarvis wants to merge 1 commit into
Open
Conversation
9980ca6 to
7023c4b
Compare
7023c4b to
9273847
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an optional PostgreSQL-only native materializer packaged as the companion gem
mini_sql-pg_native.Install path:
The PostgreSQL deserializer attempts to load
mini_sql/pg_nativeif present. If the companion gem is not installed, behavior is unchanged. This keepsrequire "mini_sql"from loadingpgfor non-PostgreSQL users. The native path can be disabled withMINI_SQL_PG_NATIVE=0.The PR also updates CI from
actions/cache@v2/checkout@v2to v4, because GitHub now hard-fails the old cache action.The native extension accelerates
MiniSql::Postgres::Connection#queryand#query_eachrow object materialization by reusing pg's own result type map and setting row instance variables directly from C. Other adapters are unchanged.Notes
query_decoratorintentionally falls back to the Ruby materializer to preserve decorator behavior.mini_sql.mini_sqlgem package. The Gemfile/Rakefile now specifymini_sqlexplicitly because Bundler sees two gemspecs in the repo.pg.h,t_pg_result,t_typemap), so the companion gem constrainspgto>= 1.6,< 1.7.query_each/query_each_hashnow initialize the PostgreSQL type map before entering single-row mode; native testing exposed that lazy initialization aftersend_querycan conflict with a busy connection.Benchmarks
Short local benchmark, Ruby 3.4.8, pg 1.6.3, PostgreSQL 18.4, local socket.
Simple materialization-only benchmark:
Approximate gain:
Earlier full-query benchmarks showed ~5-22% gains depending on row width/type mix; wider typed rows are increasingly dominated by pg type decoding.
Testing
Passed:
Packaging smoke:
gem build mini_sql-pg_native.gemspec gem build mini_sql.gemspec gem install ./mini_sql-1.6.0.gem ./mini_sql-pg_native-1.6.0.gem --local --no-document --ignore-dependencies ruby -e 'require "mini_sql"; p defined?(MiniSql::Postgres::Native::RowMaterializer)'Output:
"constant"Full
rake testwas attempted but this local container is not a clean mini_sql test environment: MySQL server is unavailable, and sqlite3 2.9.4 causes existing SQLite failures where the gemspec asks for sqlite3~> 1.4.4. The PostgreSQL tests above passed.